package com.fare.taluo.action.index;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.dayatang.domain.InstanceFactory;
import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.AnalyseQueryApplication;
import com.fare.taluo.application.FreightPriceApplication;
import com.fare.taluo.application.analyse.LowAnalyApplication;
import com.fare.taluo.application.plane.AnalyseService;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.application.plane.city.PortApplication;
import com.fare.taluo.application.plane.flight.FlightInfoApplication;
import com.fare.taluo.application.plane.income.OccupRateApplication;
import com.fare.taluo.application.plane.mycare.UserCareLineApplication;
import com.fare.taluo.auth.security.ContextLoginUser;
import com.fare.taluo.auth.security.LogonUserCertificate;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.util.I18nUtil;
import com.fare.taluo.util.RandomUtils;
import com.fare.taluo.util.XmlUtil;
import com.fare.taluo.util.convert.DoubleConvert;
import com.fare.taluo.vo.core.CityEntityVO;
import com.fare.taluo.vo.core.FlightInfoVO;
import com.fare.taluo.vo.core.LowestPriceCompareVo;
import com.fare.taluo.vo.core.OccupRateEntityVO;
import com.fare.taluo.vo.core.PlaneInfo;
import com.fare.taluo.vo.core.PortEntityVO;
import com.fare.taluo.vo.core.SourceEntityVO;
import com.fare.taluo.vo.core.UserCareLineEntityVO;
import com.fare.taluo.vo.core.fdc.IndexPriceVo;
import com.fare.util.PriceUtil;

/**
 * 首页Action
 */
@Controller("indexAction")
@Scope("prototype")
public class IndexAction extends BaseFdcAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8365259951309195932L;

	{
		 Locale locale = super.getLocale();
		 globalLowestPrice = I18nUtil.getProperties(locale).get("income.globalLowestPrice");
		 myLowestPrice = I18nUtil.getProperties(locale).get("income.myLowestPrice");
		 lowestPriceTrend = I18nUtil.getProperties(locale).get("income.lowestPriceTrend")+" ";
		 price = I18nUtil.getProperties(locale).get("income.price");
		serviceProvider = I18nUtil.getProperties(locale).get("income.serviceProvider");
		flightBatchTime= I18nUtil.getProperties(locale).get("income.flightBatchTime"); 
		grabChannel= I18nUtil.getProperties(locale).get("income.grabChannel");
		grabTime= I18nUtil.getProperties(locale).get("income.grabTime");
		flightTime = I18nUtil.getProperties(locale).get("income.flightTime");
		String eee = I18nUtil.getProperties(locale).get("login.experienceVersion");
//		System.out.println(eee);
		one=I18nUtil.getProperties(locale).get("channelPage.monday");
		two=I18nUtil.getProperties(locale).get("channelPage.tuesday");
		three=I18nUtil.getProperties(locale).get("channelPage.wednesday");
		four=I18nUtil.getProperties(locale).get("channelPage.thursday");
		five=I18nUtil.getProperties(locale).get("channelPage.friday");
		six=I18nUtil.getProperties(locale).get("channelPage.saturday");
		seven=I18nUtil.getProperties(locale).get("channelPage.sunday");
	}
	@Resource(name = "lowAnalyApplication")
	private LowAnalyApplication lowAnalyService;
	@Resource(name = "sourceApplication")
	private SourceApplication sourceApplication;
	@Resource(name = "analyseQueryApplication")
	private AnalyseQueryApplication analyseQueryApplication;
	@Resource(name = "portApplication")
	private PortApplication portApplication;
	@Resource(name = "userCareLineApplication")
	private UserCareLineApplication userCareLineApplication;
	@Resource(name = "occupRateApplication")
	private OccupRateApplication occupRateApplication;// flightInfoApplication
	@Resource(name = "flightInfoApplication")
	private FlightInfoApplication flightInfoApplication;
	private String idToaClass;
	
	List<PlaneInfo> dataTempListAlls;

	public FreightPriceApplication getFreightPriceApplication() {
		return freightPriceApplication;
	}

	public void setFreightPriceApplication(
			FreightPriceApplication freightPriceApplication) {
		this.freightPriceApplication = freightPriceApplication;
	}

	@Resource(name = "freightPriceApplication")
	private FreightPriceApplication freightPriceApplication;

	private List<List<PlaneInfo>> dataList = new ArrayList<List<PlaneInfo>>();
	private List<SourceEntityVO> sourceLists;
	private String data;
	private String beginDateAfterToday;
	private String endDateAfterToday;
	private String depCityCode; // 出发城市
	private String arrCityCode;// 到达城市
	private int isCity;// 航线设置是否为城市
	private String grapDate; // 抓取日期
	private String action;
	private List<PortEntityVO> toPort;
	private List<PortEntityVO> arrPort;
	// 时间选择框
	private String hdate;
	private List<LowestPriceCompareVo> vos;
	private String sope_Time;// 下拉框时间范围选择
	private List<String> listDate = new ArrayList<String>();// 日期集合
	private List<String> list_str = new ArrayList<String>();
	private List<UserCareLineEntityVO> citylist = new ArrayList<UserCareLineEntityVO>();
	private String company_code;// /用户渠道Key值
	private String globalLowestPrice ;
	private String myLowestPrice ;
	private String lowestPriceTrend;
	private String price;
	private String	serviceProvider ;
	private String	flightBatchTime; 
	private String	grabChannel ;
	private String grabTime ;
	private String flightTime;
	
	private String one;
	private String two;
	private String three;
	private String four;
	private String five;
	private String six;
	private String seven;
	
	public String toAnalyseJSP() {
		returnPageURL = "/fare/_zuidijiaduibi.jsp";
		return "dispatcher";
	}

	public String toIncomeJSP() throws ParseException {
		this.getChioceDateByshow();

		LogonUserCertificate user = ContextLoginUser.getLoginUser();
		citylist = userCareLineApplication.findCareLineVO(user.getLocalUserId());
		Locale locale = super.getLocale();
		/*for(UserCareLineEntityVO careLine:citylist){
			if(careLine.getArrivalcity().indexOf("(")>0){
				careLine.setArrivalcity(careLine.getArrivalcity().substring(0, careLine.getArrivalcity().indexOf("(")));
			}
			if(careLine.getDepartcity().indexOf("(")>0){
				careLine.setDepartcity(careLine.getDepartcity().substring(0, careLine.getDepartcity().indexOf("(")));
			}
			
			careLine.setArrivalcity(null==I18nUtil.getProperties(locale).get(careLine.getArrivalcity())?careLine.getArrivalcity():
				I18nUtil.getProperties(locale).get(careLine.getArrivalcity()));
			careLine.setDepartcity(null==I18nUtil.getProperties(locale).get(careLine.getDepartcity())?careLine.getDepartcity():
				I18nUtil.getProperties(locale).get(careLine.getDepartcity()));
		}*/
		//国际化改成三字码
		I18nUtil.cityCodeI18N(citylist, locale);
		
		request.setAttribute("maxDate", DateUtils.getDateAfter(29));//目前只支持30天的数据 
		returnPageURL = "/jsp/income_index.jsp";
		return "dispatcher";
	}

	public void analyse2() throws Exception {
		this.getChioceDateByshow();
	}

	public IndexPriceVo priceVo = null;
	/** 全网最低价 */
	private static List<PlaneInfo> lowerList;
	PlaneInfo rightMyFlightLowers = new PlaneInfo(),
			rightFlightLowers = new PlaneInfo();

	/**
	 * 首页第一张报表
	 */
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	public void analyseChart() {
//		if (StringUtils.isNotEmpty(getAction())) {
//			if (getAction().equals("two")) {// 第二个报表提交不用查询
//				return;
//			}
//		} else {
//			if (dataList != null)
//				dataList = new ArrayList<List<PlaneInfo>>();
//			if (lowerList != null)
//				lowerList = new ArrayList<PlaneInfo>();// 重新查询
//		}
		sourceLists = sourceApplication.findAllSourceEntity();


		String today = DateUtils.formatDay(new Date(), "yyyyMMdd");// qrday.replace("-",
																	// "");
		/** 放置需要在页面显示的程线 **/
		List<SourceEntityVO> findList = new ArrayList();
		List<String> toCode = new ArrayList<String>();
		List<String> arrCode = new ArrayList<String>();
		List<CityEntityVO> cityEntities=new ArrayList<CityEntityVO>();
		if (isCity == 1) {
			cityEntities=portApplication.findCityEntityByCityCode(depCityCode);
			if(cityEntities.size()>0){
				String cityId=String.valueOf(cityEntities.get(0).getId());
				toPort = portApplication.findPortEntityByCityCode(cityId);
				if (toPort.size() > 0) {
					for (int i = 0; i < toPort.size(); i++) {
						toCode.add(toPort.get(i).getPortCode());
					}
				}
			}
			cityEntities=portApplication.findCityEntityByCityCode(arrCityCode);
			if(cityEntities.size()>0){
				String cityId=String.valueOf(cityEntities.get(0).getId());
				arrPort = portApplication.findPortEntityByCityCode(cityId);
				if (arrPort.size() > 0) {
					for (int i = 0; i < arrPort.size(); i++) {
						arrCode.add(arrPort.get(i).getPortCode());
					}
				}
			}
			
		} else {
			toCode.add(depCityCode);
			arrCode.add(arrCityCode);
		}
		long stime = System.currentTimeMillis();
		logger.debug("首页第一张报表analyseChart====");
		List<String> dateList = null;
		LogonUserCertificate user = ContextLoginUser.getLoginUser();
		try {
			for (Iterator iterator = sourceLists.iterator(); iterator.hasNext();) {
				SourceEntityVO svo = (SourceEntityVO) iterator.next();
				if (svo.getHbaseKey().equals(user.getSourceKey())) {
					company_code = svo.getHbaseKey();
					break;
				}
			}

			dateList = AnalyseService.calculateDaysByNow(grapDate,beginDateAfterToday, endDateAfterToday);

			// 需要显示的字段
//			List<HBaseFilterVO> vos = new ArrayList<HBaseFilterVO>();
//			vos.add(new HBaseFilterVO("planeinfo", "lowerPrice"));
//			vos.add(new HBaseFilterVO("planeinfo", "carrierName"));
//			vos.add(new HBaseFilterVO("planeinfo", "flightId"));
//			vos.add(new HBaseFilterVO("planeinfo", "flightBatchDate"));
//			vos.add(new HBaseFilterVO("planeinfo", "flightBatchStartTime"));
//			vos.add(new HBaseFilterVO("planeinfo", "flightBatchEndTime"));
//			vos.add(new HBaseFilterVO("planeinfo", "grabChannel"));
//			vos.add(new HBaseFilterVO("planeinfo", "grabDate"));
			// 我的最低价
			List<?> myList = new ArrayList();
			String my_SRK = "";
			String my_ERK = "";
			List<PlaneInfo> dataTempListAll = new ArrayList<PlaneInfo>();
			
			//查出所有数据(不作处理，由预处理来做)
			dataTempListAll=dataTempListAlls=freightPriceApplication.findByConditions(company_code,  toCode.get(0),arrCode.get(0), null);

			dataList.add(dataTempListAll);
			// 改成全网最低价哦 除去我的最低价
			List<List<PlaneInfo>> qudaoList = new ArrayList();
			
			List<PlaneInfo> tmpList=freightPriceApplication.findByConditions(null,toCode.get(0),arrCode.get(0), null);
			//过滤hbaseKey
			if(tmpList.size()>0){
				for(int k=0;k<tmpList.size();k++){
					PlaneInfo planeInfos=new PlaneInfo();
					planeInfos=tmpList.get(k);
					List<PlaneInfo> tmpListAll = new ArrayList<PlaneInfo>();
					for (Iterator iterator = sourceLists.iterator(); iterator.hasNext();){
						SourceEntityVO svo = (SourceEntityVO) iterator.next();
						if(planeInfos.getHbaseKey().equals(svo.getHbaseKey())){
							tmpListAll.add(planeInfos);
						}
						
					}
					qudaoList.add(tmpListAll);
				}
				
			}

			// 找出最低价
			lowerList = PriceUtil.getLowsPlaneInfo(dateList, qudaoList);
			String xml = this.getLowersXML(dataList.get(0), lowerList,dateList, lowestPriceTrend);

			/**
			 * 根据选择航线变化航线最低价，从两个集合中查找出 ,一进来是当天的最低价
			 * 计算公式：（目标航线目标航班日期）我的最低价/市场最低价-1，为正的，显示我比市场“高”，为负的显示我比市场“低”
			 * 这个比较在Jsp里面实现
			 */

			if (dataList != null && !dataList.isEmpty()) {
				List<PlaneInfo> myprice = dataList.get(0);
				for (PlaneInfo info : myprice) {
					if (info.getFlightBatchDate().equals(dateList.get(0))) {// 第一次进来
						rightMyFlightLowers = info;
						break;
					}
				}

			}
			if (lowerList != null && lowerList.size() > 0) {
				/** 全网最低价 */
				for (PlaneInfo info : lowerList) {
					if (info.getFlightBatchDate().equals(dateList.get(0) + "")) {
						rightFlightLowers = info;
						break;
					}
				}
			}
			/** 组装IndexPriceVo */
			// priceVo
			priceVo = new IndexPriceVo();
			priceVo.setHightOrLower(rightMyFlightLowers.getLowerPrice(),rightFlightLowers.getLowerPrice(),super.getLocale());
			priceVo.setMyFlightNO(rightMyFlightLowers.getFlightId());
			priceVo.setMarketFlightNo(rightFlightLowers.getFlightId());

			data = "{\"json\":" + com.fare.taluo.util.JsonUtil.toJson(priceVo)
					+ ",\"classID\":"
					+ com.fare.taluo.util.JsonUtil.toJson(idToaClass)
					+ ",\"xml\":\"" + xml + "\"}";

		} catch (Exception e) {
			e.printStackTrace();
		}
		super.toJSONOut(data);
		logger.debug("首页第一张报表analyseChart====耗时："+(System.currentTimeMillis()-stime));
	}

	private String qrday;

	/**
	 * 首页第二张报表 rowkey： 渠道_起点(使用三字码)_终点(使用三字码)_(航班号)_航班时间(年月日时)---当天情况查询
	 * 根据这一天所有航班，查询，一进来时是当天
	 * 
	 */
	@SuppressWarnings("rawtypes")
	public void analyseBarChart() {
		JSONArray ja = new JSONArray();
		String flag="success";
		long stime = System.currentTimeMillis();
		logger.debug("首页第二张报表analyseBarChart====");
		LogonUserCertificate currentUser = ContextLoginUser.getLoginUser();
		try {
			qrday = this.hdate;
			if (StringUtils.isBlank(qrday)) {
				qrday = DateUtils.getDateStr("yyyy-MM-dd");
			} else if (qrday.indexOf("/") != -1) {// 没有找到返加-1
				qrday = (DateUtils.dateToStr(new Date(), "yyyy") + "-"
						+ qrday.split("/")[0] + "-" + qrday.split("/")[1]);
			} else {
				// /qrday =(DateUtils.dateToStr(new Date(),
				// "yyyy")+"-"+qrday.split("/")[0]+"-"+qrday.split("/")[1]);
			}
			List<String> toCode = new ArrayList<String>();
			List<String> arrCode = new ArrayList<String>();
			
			List<CityEntityVO> cityEntities=new ArrayList<CityEntityVO>();
			if (isCity == 1) {
				cityEntities=portApplication.findCityEntityByCityCode(depCityCode);
				if(cityEntities.size()>0){
					String cityId=String.valueOf(cityEntities.get(0).getId());
					if (toPort == null) {
						toPort = portApplication.findPortEntityByCityCode(cityId);
						if (toPort.size() > 0) {
							for (int i = 0; i < toPort.size(); i++) {
								toCode.add(toPort.get(i).getPortCode());
							}
						}
					} else {
						if (toPort.size() > 0) {
							for (int i = 0; i < toPort.size(); i++) {
								toCode.add(toPort.get(i).getPortCode());
							}
						}
					}
				}
				cityEntities=portApplication.findCityEntityByCityCode(arrCityCode);
				if(cityEntities.size()>0){
					String cityId=String.valueOf(cityEntities.get(0).getId());
					if (arrPort == null) {
						arrPort = portApplication.findPortEntityByCityCode(cityId);
						if (arrPort.size() > 0) {
							for (int i = 0; i < arrPort.size(); i++) {
								arrCode.add(arrPort.get(i).getPortCode());
							}
						}
					} else {
						if (arrPort.size() > 0) {
							for (int i = 0; i < arrPort.size(); i++) {
								arrCode.add(arrPort.get(i).getPortCode());
							}
						}
					}
				}
			} else {
				toCode.add(depCityCode);
				arrCode.add(arrCityCode);
			}

			// /根据 CODE 找出航线
			if (sourceLists == null) {
				sourceLists = sourceApplication.findAllSourceEntity();
			}
			String carry_key = "";
			for (Iterator iterator = sourceLists.iterator(); iterator.hasNext();) {
				SourceEntityVO svo = (SourceEntityVO) iterator.next();
				if (svo.getHbaseKey().equals(currentUser.getSourceKey())) {
					company_code = svo.getHbaseKey();
					carry_key = svo.getCarrierKey();
					break;
				}
			}


			List<List<PlaneInfo>> datas = new ArrayList<List<PlaneInfo>>();
			
			//先查询出所有的数据，然后再过滤出航班号
			List<PlaneInfo> data=freightPriceApplication.findPlaneInfoProperty(company_code,  depCityCode , arrCityCode, qrday, null);//fvo.getFlightNo()
			
			
			if(data.size()>0){
				datas.add(data);
			}
			
			List<PlaneInfo> infos = new ArrayList<PlaneInfo>();
			for (List<PlaneInfo> list : datas) {
				for (PlaneInfo info : list) {
					if (info != null) {
						infos.add(info);
					}
				}
			}
			// 计算航班最低价
			HashMap<String, PlaneInfo> mpprice = analyseQueryApplication.caluteHangbanLowPrice(infos);
			//随要获得两个航班，用于座公里收入及客座率
			List<FlightInfoVO> flights = InstanceFactory.getInstance(FlightInfoApplication.class).findByLine(depCityCode, arrCityCode);
			HashMap<String, List<String>> hsmap = getHashMap(mpprice, qrday,carry_key,
					flights!=null&&flights.size()>2?flights.subList(0, 2):null);

			/** 我的最优公里数 */

			/** 我的最优客座率 */		
			//this.comparaMyOccupRate(dataList, lowerList, hsmap, toCode,arrCode, qrday, carry_key);// 查出这一天的最低价
			if (infos == null || infos.isEmpty()) {
				flag="error";
//				incomeVo.setIsHeadDate("0");// 表示数据为空,Flash 不显示
			}
			JSONObject jo = new JSONObject();
			jo.put("occupVo", JSONObject.fromObject(occupVo).toString());
			jo.put("incomeVo", JSONObject.fromObject(incomeVo).toString());
			ja.add(jo.toString());
			 Locale locale = super.getLocale();
			 XmlUtil.changeLocale(locale);
			if (hsmap.size() > 5) {
				/** 一屏显示5个 */
				Iterator it = hsmap.entrySet().iterator();
				int i = 1;
				HashMap<String, List<String>> hsmap2 = new HashMap<String, List<String>>();
				while (it.hasNext()) {
					Map.Entry<String, List<String>> entry = (Map.Entry) it.next();

					hsmap2.put(entry.getKey(), entry.getValue());
					if (i % 5 == 0 && i != 0) {
						String s = "{\"xml\":\"" + XmlUtil.getXML3(hsmap2)
								+ "\"}";
						ja.add(s);
						hsmap2 = new HashMap<String, List<String>>();
					}
					i++;
				}
				if (hsmap2.size() > 0) {
					String s = "{\"xml\":\"" + XmlUtil.getXML3(hsmap2) + "\"}";
					ja.add(s);
				}

			} else {
				String s = "{\"xml\":\"" + XmlUtil.getXML3(hsmap) + "\"}";
				ja.add(s);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		ja.add(flag);
		super.toJSONOut(ja.toString());
		logger.debug("首页第二张报表analyseBarChart====耗时："+(System.currentTimeMillis()-stime));
	}

	
	
	private IndexPriceVo occupVo;// myOccupPlane;
	private IndexPriceVo incomeVo;

	/**
	 * 计算出我的最优客座率 HashMap 里面有航班号
	 * 
	 * @param map
	 *            第二张报表的数据
	 * @param toCode
	 *            出发城市 三字码
	 * @param arrCode
	 *            到达城市三字码
	 * @param flightDay
	 *            飞行日期
	 */
	public void comparaMyOccupRate(List<List<PlaneInfo>> myList,
			List<PlaneInfo> wlist, HashMap<String, List<String>> map,
			String toCode, String arrCode, String flightDay, String carry_key) {
		priceVo = new IndexPriceVo();
		if (StringUtils.isNotEmpty(action) && action.equals("two")) {
			if (myList != null && !myList.isEmpty()) {// /找出这天我的最低价// 已经是最低价，找出这天的价格
				List<PlaneInfo> mylowers = myList.get(0);
				for (PlaneInfo p : mylowers) {
					if (p.getFlightBatchDate().equals(flightDay)) {
						rightMyFlightLowers = p;
						break;
					}
				}
			}
			for (PlaneInfo wp : wlist) {
				if (wp.getFlightBatchDate().equals(flightDay)) {
					rightFlightLowers = wp;
					break;
				}
			}
			priceVo.setAction(action);
			priceVo.setHightOrLower(rightMyFlightLowers.getLowerPrice(),rightFlightLowers.getLowerPrice(),super.getLocale());
			priceVo.setMyFlightNO(rightMyFlightLowers.getFlightId());
			priceVo.setMarketFlightNo(rightFlightLowers.getFlightId());
			this.priceVo = priceVo;
		}
		/**
		 * 找出我的最优座公里，客座率
		 */
		OccupRateEntityVO myOccupPlane = new OccupRateEntityVO();
		String income_flight = "";
		double income = 0l;// /最优客座率最大的4
		for (String flight : map.keySet()) {
			if (map.get(flight).size() > 2) {
				if (StringUtils.isEmpty(flightDay)) {// /如果时间为空 这个基本没有用
					double d = Double.parseDouble(map.get(flight).get(3));
					double kz = 0l;
					if (map.get(flight).size() > 3) {
						kz = Double.parseDouble(map.get(flight).get(4));
					}
					if (kz > income) {
						income_flight = flight;
						income = kz;
						myOccupPlane.setFlightInfo(flight);
						myOccupPlane.setOccupRate2(Double.valueOf(kz));
						myOccupPlane.setIncome2(Double.valueOf(d));
						myOccupPlane.setPrice((long) (Double.parseDouble(map.get(flight).get(0))));
					}
				} else {// /如果时间不为空 则要找到这一天的数据
						// System.out.println(map.get(flight).get(2)+ " ----");
					if (map.get(flight).get(2).equals(flightDay)) {
						double d = Double.parseDouble(map.get(flight).get(3));
						double kz = 0l;
						if (map.get(flight).size() > 3) {
							kz = Double.parseDouble(map.get(flight).get(4));
						}
						if (kz > income) {
							income_flight = flight;
							income = kz;
							myOccupPlane.setFlightInfo(flight);
							myOccupPlane.setIncome2(Double.valueOf(d));
							myOccupPlane.setOccupRate2(Double.valueOf(kz));
							myOccupPlane.setPrice((long) (Double.parseDouble(map.get(flight).get(0))));
						}
					}
				}
			}
		}
		OccupRateEntityVO myIncomePlane = new OccupRateEntityVO();
		String occup_flight = "";
		double occup = 0l;// /最最大的 3 座公里
		for (String flight : map.keySet()) {
			if (map.get(flight).size() > 2) {
				if (StringUtils.isEmpty(flightDay)) {// /如果时间为空
					double d = Double.parseDouble(map.get(flight).get(3));
					double kz = 0l;
					if (map.get(flight).size() > 3) {
						kz = Double.parseDouble(map.get(flight).get(4));
					}
					if (d > occup) {
						income_flight = flight;
						occup = d;
						myIncomePlane.setFlightInfo(flight);
						myIncomePlane.setIncome2(Double.valueOf(d));
						myIncomePlane.setOccupRate2(Double.valueOf(kz));
						myIncomePlane.setPrice((long) (Double.parseDouble(map.get(flight).get(0))));
					}
				} else {
					if (map.get(flight).get(2).equals(flightDay)) {
						double d = Double.parseDouble(map.get(flight).get(3));
						double kz = 0l;
						if (map.get(flight).size() > 3) {
							kz = Double.parseDouble(map.get(flight).get(4));
						}
						if (d > occup) {
							income_flight = flight;
							occup = d;
							myIncomePlane.setFlightInfo(flight);
							myIncomePlane.setIncome2(Double.valueOf(d));
							myIncomePlane.setOccupRate2(Double.valueOf(kz));
							myIncomePlane.setPrice((long) (Double.parseDouble(map.get(flight).get(0))));
						}
					}
				}
			}
		}
		/**
		 * 计算包括我 最优客座率 HashMap 里面有航班号
		 */
		OccupRateEntityVO wOccupPlane = new OccupRateEntityVO();
		OccupRateEntityVO wIncomePlane = new OccupRateEntityVO();
		/** 航班号集合 在全网最低价里面 lowerList */

		List<OccupRateEntityVO> occupList = new ArrayList();
		if (sourceLists == null) {
			sourceLists = sourceApplication.findAllSourceEntity();
		}
		LogonUserCertificate currentUser = ContextLoginUser.getLoginUser();
		String companyCode = "";
		for (SourceEntityVO vo : sourceLists) {
			if (vo.getHbaseKey().equals(currentUser.getSourceKey())) {
				companyCode = vo.getCarrierKey();
			}
		}
		String toCodeName = null;
		String arrCodeName = null;
		if (isCity == 1) {
			if (toPort == null) {
				toCodeName = portApplication.findPortEntityByCityCode(depCityCode).get(0).getCityName();
			} else {
				 toCodeName = toPort.get(0).getCityName();
			}
			if (arrPort == null) {
				arrCodeName = portApplication.findPortEntityByCityName(arrCityCode).getCityName();
			} else {
				 arrCodeName = arrPort.get(0).getCityName();
			}
		}
		if (toCodeName.equals("北京(PEK)")) {
			toCodeName = "北京";
		}
		if (arrCodeName.equals("北京(PEK)")) {
			arrCodeName = "北京";
		}
		long stime = System.currentTimeMillis();
		logger.debug("查询findOccupRateCondition2====");
		occupList = occupRateApplication.findOccupRateCondition2(toCodeName	+ "-" + arrCodeName, flightDay);
		logger.debug("查询findOccupRateCondition2====耗时："+(System.currentTimeMillis()-stime));
		if (occupList != null && occupList.size() > 0) {
			Collections.sort(occupList, new SortOccuHight());
			wOccupPlane = occupList.get(0);
			Collections.sort(occupList, new SortIncomeHight());
			wIncomePlane = occupList.get(0);
		}
		occupVo = new IndexPriceVo();
		incomeVo = new IndexPriceVo();
		occupVo.setType(2);
		incomeVo.setType(1);
		occupVo.setHightOrLower(myOccupPlane.getOccupRate2() + "",wOccupPlane.getOccupRate2() + "",super.getLocale());
		occupVo.setMyFlightNO(myOccupPlane.getFlightInfo());
		occupVo.setMarketFlightNo(wOccupPlane.getFlightInfo());
		incomeVo.setHightOrLower(myIncomePlane.getIncome2() + "",wIncomePlane.getIncome2() + "",super.getLocale());
		incomeVo.setMyFlightNO(myIncomePlane.getFlightInfo());
		incomeVo.setMarketFlightNo(wIncomePlane.getFlightInfo());
	}

	/**
	 * 用于首页趋势图报表显示
	 * 
	 * @param airPrice
	 *            官网最低价哦
	 * @param infos
	 *            渠道最低价哦
	 * @param dates
	 *            日期
	 * @param tableName
	 * @return
	 * @throws Exception
	 */
	private String getLowersXML(List<PlaneInfo> airPrice,
			List<PlaneInfo> infos, List<String> dates, String tableName)
			throws Exception {
		PlaneInfo lastInfo = new PlaneInfo();// /上一个值
		PlaneInfo nowInfo = new PlaneInfo();// /记录下个值上一个值
		
		Locale locale = super.getLocale();

		List<PlaneInfo> planeList2 = null;
		double lowerListForall = 0.0;
		double min = 9999999.0;
		double min2 = 99999999.0;
		int m = 0, n = 0;
		List<Double> lowerPriceAll = new ArrayList<Double>();

		for (String date : dates) {
			for (Iterator iterator = airPrice.iterator(); iterator.hasNext();) {
				PlaneInfo airPrices = (PlaneInfo) iterator.next();
				n++;
				if (min > Double.parseDouble(airPrices.getLowerPrice())) {
					min = Double.parseDouble(airPrices.getLowerPrice());
				}
			}
			for (Iterator iterator = infos.iterator(); iterator.hasNext();) {
				PlaneInfo info = (PlaneInfo) iterator.next();
				m++;
				if (min2 > Double.parseDouble(info.getLowerPrice())) {
					min2 = Double.parseDouble(info.getLowerPrice());
				}

			}
			if (min2 > min) {
				min2 = min;
			}

		}
		lowerListForall = min2 - 100;

		StringBuffer XML = new StringBuffer(
				"<?xml version='1.0'?>"
						+ "<chart caption=''  numberPrefix='￥' "
						+ "sformatNumberScale='10'  syncAxisLimits='1' showValues='0' rotateValues='0' showSum='0' "
						+ "yAxisValuesPadding='15' chartRightMargin='25'  labelDisplay='ROTATE' baseFontSize='10'"
						+ "yAxisMinValue='"
						+ lowerListForall
						+ "' slantLabels='0'  bgColor='FFFFFF' canvasBgColor='FFFFFF' showBorder='0'><categories>");

		// categories子集category个数与dataset子集set个数要一致
		for (String s : dates) {
			XML.append("<category label='" + s.substring(5) + "'/>");
		}

		XML.append("</categories>");
		// String color = "#4A6FB1";//3300CC
		String color = "#8DA71E";
		XML.append("<dataset seriesName='"+myLowestPrice+"' anchorRadius='5' color='"
				+ color + "'>");

		int k = 0;// 循环次数

		for (String date : dates) {
			int i = 0;
			for (Iterator iterator = airPrice.iterator(); iterator.hasNext();) {
				PlaneInfo info = (PlaneInfo) iterator.next();
				if (info.getFlightBatchDate().equals(date)) {
					i = 2;
					if (k == 0) {// 上一次的值
						lastInfo = info;
						XML.append("<set value='"
								+ info.getLowerPrice()
								+ "' toolText='"+price+"： ￥"
								+ info.getLowerPrice()
								+ "&#xA;"+serviceProvider+"："
								+  (null==I18nUtil.getProperties(locale).get(info.getCarrierName())?info.getCarrierName():I18nUtil.getProperties(locale).get(info.getCarrierName()))
								+ " "
								+ info.getFlightId()
								+ "&#xA;"+flightTime+"： "
								+ info.getFlightBatchDate()
								+ "&#xA;"+flightBatchTime+"："
								+ info.getFlightBatchStartTime().substring(11, 16)
								+ "-"
								+ info.getFlightBatchEndTime().substring(11, 16) 
								+ "&#xA;"+grabChannel+"：" 
								+ (null==I18nUtil.getProperties(locale).get(info.getGrabChannel())?info.getGrabChannel():I18nUtil.getProperties(locale).get(info.getGrabChannel()))
								+ "&#xA;"+grabTime+"：" + info.getGrapDateHStr() + "'/>");
						break;
					} else {// 记录当前的值
						nowInfo = info;
					}
					// //XML.append("<set value='"+info.getLowprPrice()+"'/>");

				}
			}
			if (i == 0) {
				k = k + 1;// /循环次数
			}
			if (i == 2 && k > 0) {
				for (int j = 0; j < k; j++) {
					if (lastInfo == null || null == lastInfo.getLowerPrice()) {
						XML.append("<set value='' />");
					} else {
						XML.append("<set value='"
								+ (Double.parseDouble(lastInfo.getLowerPrice()) + Double
										.parseDouble(nowInfo.getLowerPrice()))
								/ 2
								+ "' showValue='false' dashed ='1'  anchorRadius='0' toolText='价     格： ￥"
								+ lastInfo.getLowerPrice()
								+ "&#xA;"+serviceProvider+"："
								+ (null==I18nUtil.getProperties(locale).get(lastInfo.getCarrierName())?lastInfo.getCarrierName():I18nUtil.getProperties(locale).get(lastInfo.getCarrierName()))
								+ " "
								+ lastInfo.getFlightId()
								+ "&#xA;"+flightTime+"： "
								+ lastInfo.getFlightBatchDate()
								+ "&#xA;"+flightBatchTime+"："
								+ lastInfo.getFlightBatchStartTime().substring(11, 16)
								+ "-"
								+ lastInfo.getFlightBatchEndTime().substring(11, 16) 
								+ "&#xA;"+grabChannel+"："
								+( null==I18nUtil.getProperties(locale).get(lastInfo.getGrabChannel())?lastInfo.getGrabChannel():I18nUtil.getProperties(locale).get(lastInfo.getGrabChannel()))
								+ "&#xA;"+grabTime+"："
								+ lastInfo.getGrapDateHStr() + "'/>");
					}
				}
				XML.append("<set value='"
						+ nowInfo.getLowerPrice()
						+ "' toolText='"+price+"： ￥"
						+ nowInfo.getLowerPrice()
						+ "&#xA;"+serviceProvider+"："
						+ (null==I18nUtil.getProperties(locale).get(nowInfo.getCarrierName())?nowInfo.getCarrierName():I18nUtil.getProperties(locale).get(nowInfo.getCarrierName()))
						+ " "
						+ nowInfo.getFlightId()
						+ "&#xA;"+flightTime+"： "
						+ nowInfo.getFlightBatchDate()
						+ "&#xA;"+flightBatchTime+"："
						+ nowInfo.getFlightBatchStartTime().substring(11, 16)
						+ "-"
						+ nowInfo.getFlightBatchEndTime().substring(11, 16) 
						+ "&#xA;"+grabChannel+"："
						+ (null==I18nUtil.getProperties(locale).get(nowInfo.getGrabChannel())?nowInfo.getGrabChannel():I18nUtil.getProperties(locale).get(nowInfo.getGrabChannel()) )
						+ "&#xA;"+grabTime+"："
						+ nowInfo.getGrapDateHStr() + "'/>");
				k = 0;
				lastInfo = nowInfo;
				nowInfo = null;
			}

		}
		XML.append("</dataset>");
		// color = "#8DA71E";
		color = "#4A6FB1";
		
		XML.append("<dataset seriesName='"+globalLowestPrice+"' anchorRadius='5' color='"
				+ color + "'>");
		k = 0;
		lastInfo = null;
		nowInfo = null;
		for (String date : dates) {
			int i = 0;
			for (Iterator iterator = infos.iterator(); iterator.hasNext();) {
				PlaneInfo info = (PlaneInfo) iterator.next();
				if (info.getFlightBatchDate().equals(date)) {
					i = 2;
					if (k == 0) {// 上一次的值
						lastInfo = info;
						XML.append("<set value='"
								+ info.getLowerPrice()
								+ "' toolText='"+price+"： ￥"
								+ info.getLowerPrice()
								+ "&#xA;"+serviceProvider+"："
								+ (null==I18nUtil.getProperties(locale).get(info.getCarrierName())?info.getCarrierName():I18nUtil.getProperties(locale).get(info.getCarrierName()))
								+ " "
								+ info.getFlightId()
								+ "&#xA;"+flightTime+"： "
								+ info.getFlightBatchDate()
								+ "&#xA;"+flightBatchTime+"："
								+ info.getFlightBatchStartTime().substring(11, 16)
								+ "-"
								+ info.getFlightBatchEndTime().substring(11, 16)
								+ "&#xA;"+grabChannel+"：" + (null==I18nUtil.getProperties(locale).get(info.getGrabChannel())?info.getGrabChannel():I18nUtil.getProperties(locale).get(info.getGrabChannel()))
								+ "&#xA;"+grabTime+"：" + info.getGrapDateHStr() + "'/>");
						break;
					} else {// 记录当前的值
						nowInfo = info;
					}
				}
			}
			if (i == 0) {
				k = k + 1;// /循环次数
			}
			if (i == 2 && k > 0) {
				for (int j = 0; j < k; j++) {
					if (lastInfo == null || null == lastInfo.getLowerPrice()) {
						XML.append("<set value='' />");
					} else {
						XML.append("<set value='"
								+ (Double.parseDouble(lastInfo.getLowerPrice()) + Double
										.parseDouble(nowInfo.getLowerPrice()))
								/ 2
								+ "' showValue='false' dashed ='1'  anchorRadius='0' toolText='价     格： ￥"
								+ lastInfo.getLowerPrice()
								+ "&#xA;"+serviceProvider+"："
								+ (null==I18nUtil.getProperties(locale).get(lastInfo.getCarrierName())?lastInfo.getCarrierName():I18nUtil.getProperties(locale).get(lastInfo.getCarrierName()))
								+ " "
								+ lastInfo.getFlightId()
								+ "&#xA;"+flightTime+"： "
								+ lastInfo.getFlightBatchDate()
								+ "&#xA;"+flightBatchTime+"："
								+ lastInfo.getFlightBatchStartTime().substring(11, 16)
								+ "-"
								+ lastInfo.getFlightBatchEndTime().substring(11, 16) 
								+ "&#xA;"+grabChannel+"："
								+ (null==I18nUtil.getProperties(locale).get(lastInfo.getGrabChannel())?lastInfo.getGrabChannel():I18nUtil.getProperties(locale).get(lastInfo.getGrabChannel()))
								+ "&#xA;"+grabTime+"："
								+ lastInfo.getGrapDateHStr() + "'/>");
					}
				}
				XML.append("<set value='"
						+ nowInfo.getLowerPrice()
						+ "' toolText='"+price+"： ￥"
						+ nowInfo.getLowerPrice()
						+ "&#xA;"+serviceProvider+"："
						+ (null==I18nUtil.getProperties(locale).get(nowInfo.getCarrierName())?nowInfo.getCarrierName():I18nUtil.getProperties(locale).get(nowInfo.getCarrierName()))
						+ " "
						+ nowInfo.getFlightId()
						+ "&#xA;"+flightTime+"： "
						+ nowInfo.getFlightBatchDate()
						+ "&#xA;"+flightBatchTime+"："
						+ nowInfo.getFlightBatchStartTime().substring(11, 16)
						+ "-"
						+ nowInfo.getFlightBatchEndTime().substring(11, 16) 
						+ "&#xA;"+grabChannel+"："
						+ (null==I18nUtil.getProperties(locale).get(nowInfo.getGrabChannel())?nowInfo.getGrabChannel():I18nUtil.getProperties(locale).get(nowInfo.getGrabChannel())) 
						+ "&#xA;"+grabTime+"："
						+ nowInfo.getGrapDateHStr() + "'/>");
				k = 0;
				lastInfo = nowInfo;
				nowInfo = null;
			}

		}
		XML.append("</dataset>");
		XML.append("</chart>");

		return XML.toString();
	}

	public HashMap<String, List<String>> getHashMap(
			HashMap<String, PlaneInfo> map, String date, String carrierKey,
			List<FlightInfoVO> flights) {
		HashMap<String, List<String>> hsmap = new HashMap<String, List<String>>();
		if (map != null && map.size() > 0) {
			occupVo = new IndexPriceVo();
			incomeVo = new IndexPriceVo();
			double minIncomeV = 0;
			double minOccupV = 0;

			for (String cz : map.keySet()) {

				if (!hsmap.containsKey(cz)) {
					hsmap.put(cz, new ArrayList<String>());
				}
				PlaneInfo info = map.get(cz);
				hsmap.get(cz).add(info.getLowerPrice());// 从 0开始
				hsmap.get(cz).add(DateUtils.getPageDateStr(info.getGrabDate(),"yyyy-MM-dd hh"));//第1个
				//生成随机数
				//座公里收入
				minIncomeV = RandomUtils.random(1500, 500);
				hsmap.get(cz).add(DoubleConvert.convert(minIncomeV, 2));
				if(incomeVo.getMyPrice()==null) incomeVo.setMyPrice("1000000000");
				if(minIncomeV < Double.valueOf(incomeVo.getMyPrice())){
					incomeVo.setMyPrice(DoubleConvert.convert(minIncomeV, 2));
					incomeVo.setMyFlightNO(info.getFlightId());
				}
				//客座率
				minOccupV = RandomUtils.random(100, 80);
				hsmap.get(cz).add(DoubleConvert.convert(minOccupV, 2));
				if(occupVo.getMyPrice()==null) occupVo.setMyPrice("1000000000");
				if(minIncomeV < Double.valueOf(occupVo.getMyPrice())){
					occupVo.setMyPrice(DoubleConvert.convert(minOccupV, 2));
					occupVo.setMyFlightNO(info.getFlightId());
				}
			}
			//这里苟且一点，后面再改
			if(flights!=null && flights.size()>1 && flights.get(0)!=null) {
				incomeVo.setMarketPrice(DoubleConvert.convert(RandomUtils.random(1500l, 500l),2));
				incomeVo.setMarketFlightNo(flights.get(0).getFlightNo());
				incomeVo.setHightOrLower(incomeVo.getMyPrice(), incomeVo.getMarketPrice(),super.getLocale());
			}
			if(flights!=null && flights.size()>1 && flights.get(1)!=null) {
				occupVo.setMarketPrice(DoubleConvert.convert(RandomUtils.random(100l, 80l),2));
				occupVo.setMarketFlightNo(flights.get(1).getFlightNo());
				occupVo.setHightOrLower(occupVo.getMyPrice(), occupVo.getMarketPrice(),super.getLocale());
			}
		}

		return hsmap;
	}

	public void dobuleClickDate() throws ParseException {
		this.getChioceDateByshow();
		this.grapDate = this.sope_Time;
		this.analyseBarChart();
		// returnPageURL = "/csair/income_index.jsp";
		// return "dispatcher";

	}

	public static void main(String[] args) {
		String s = "01/01";
		System.err.println((DateUtils.dateToStr(new Date(), "yyyy") + "-"
				+ s.split("/")[0] + "-" + s.split("/")[1]));

	}

	// 定位时间轴
	public void getChioceDateByshow() throws ParseException {
		list_str.clear();
		DateFormat df = new SimpleDateFormat("MM/dd");
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if (StringUtils.isNotEmpty(this.sope_Time)) {
			if (sope_Time.indexOf("/") != -1) {// bao han
				sope_Time = (DateUtils.dateToStr(new Date(), "yyyy") + "-"
						+ sope_Time.split("/")[0] + "-" + sope_Time.split("/")[1]);
				Date d_t = DateUtils.strToDate(sope_Time, "yyyy-MM-dd");
				String d_s = DateUtils.getDateStr("yyyy-MM-dd");
				if (d_t.getTime() < (DateUtils.strToDate(d_s, "yyyy-MM-dd"))
						.getTime()) {
					sope_Time = d_s;
				}
			} else {
				// Date nowDate = new Date();
				// this.sope_Time=sdf.format(nowDate);
			}
		} else {
			Date nowDate = new Date();
			this.sope_Time = sdf.format(nowDate);
		}
		List<Date> listdate = this.getSevDayByChioce(this.sope_Time);
		for (int i = 0; i < listdate.size(); i++) {
			/*
			 * if(listdate.get(i).getDay()==0){
			 * this.list_str.add(df.format(listdate.get(i)) + "-周"+ "日"); }
			 */
			switch (listdate.get(i).getDay()) {
			case 0:
				this.list_str.add(df.format(listdate.get(i)) + "-" + seven);
				break;
			case 1:
				this.list_str.add(df.format(listdate.get(i)) + "-" + one);
				break;
			case 2:
				this.list_str.add(df.format(listdate.get(i)) + "-" + two);
				break;
			case 3:
				this.list_str.add(df.format(listdate.get(i)) + "-" + three);
				break;
			case 4:
				this.list_str.add(df.format(listdate.get(i)) + "-" + four);
				break;
			case 5:
				this.list_str.add(df.format(listdate.get(i)) + "-" + five);
				break;
			case 6:
				this.list_str.add(df.format(listdate.get(i)) + "-" + six);
				break;
			}
		}
		super.toJSONOut(JSONArray.fromObject(this.list_str).toString());
	}

	// AJAX获取日期轴
	public void getDateList() {
		DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
		List<Date> list = getDateList(30);
		Date d = null;
		Date d2 = null;
		for (int i = 0; i < list.size(); i = i + 6) {
			d = list.get(i);
			if (i + 6 >= list.size()) {
				d2 = list.get(list.size() - 1);
			} else {
				d2 = list.get(i + 6);
			}
			try {
				this.listDate.add(df.format(d) + "--" + df.format(d2));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		this.getWeekDate();

		super.toJSONOut(JSONArray.fromObject(this.list_str).toString());
	}

	// 处理日期范围返回日期范围7天为一组LIST
	public List<String> getWeekDate() {
		DateFormat df = new SimpleDateFormat("MM/dd");
		int dayNum = 0;
		if (StringUtils.isBlank(this.sope_Time)
				|| this.sope_Time.equalsIgnoreCase("0")) {
			this.sope_Time = "1";
		}
		if (StringUtils.isNotBlank(this.sope_Time)) {
			this.sope_Time.replace(" ", "");
			if (this.sope_Time.equalsIgnoreCase("1")) {
				dayNum = 7;
			}
			if (this.sope_Time.equalsIgnoreCase("2")) {
				dayNum = 13;
			}
			if (this.sope_Time.equalsIgnoreCase("3")) {
				dayNum = 19;
			}
			if (this.sope_Time.equalsIgnoreCase("4")) {
				dayNum = 25;
			}
			if (this.sope_Time.equalsIgnoreCase("5")) {
				dayNum = 31;
			}
			if (this.sope_Time.equalsIgnoreCase("6")) {
				dayNum = 37;
			}
			if (this.sope_Time.equalsIgnoreCase("7")) {
				dayNum = 42;
			}
			if (this.sope_Time.equalsIgnoreCase("8")) {
				dayNum = 45;
			}
		}
		List<Date> listdate = getDateListByWeek(dayNum);
		for (int i = 0; i < listdate.size(); i++) {
			this.list_str.add(df.format(listdate.get(i)) + "<br/>"
					+ new SimpleDateFormat("EEEE").format(listdate.get(i)));
		}
		return this.list_str;
	}

	// 返回日期范围内指定7天日期
	private static List<Date> getDateListByWeek(int dayNum) {
		int begDay = 0;
		int endDay = 0;
		// 7,13,19,25,31,37,42,45,
		if (dayNum == 7) {
			endDay = 7;
		}
		if (dayNum == 13) {
			begDay = 6;
			endDay = 13;
		}
		if (dayNum == 19) {
			begDay = 12;
			endDay = 19;
		}
		if (dayNum == 25) {
			begDay = 18;
			endDay = 25;
		}
		if (dayNum == 31) {
			begDay = 24;
			endDay = 31;
		}
		if (dayNum == 37) {
			begDay = 30;
			endDay = 37;
		}
		if (dayNum == 42) {
			begDay = 36;
			endDay = 42;
		}
		if (dayNum == 45) {
			begDay = 41;
			endDay = 45;
		}
		Date nowDate = new Date();
		Calendar c = Calendar.getInstance();
		c.setTime(nowDate);
		c.set(Calendar.DATE, c.get(Calendar.DATE) + begDay);
		Date endDate = c.getTime();

		Calendar c2 = Calendar.getInstance();
		c2.setTime(nowDate);
		c2.set(Calendar.DATE, c2.get(Calendar.DATE) + endDay);
		Date endDate2 = c2.getTime();

		int dc = (int) ((endDate2.getTime() - endDate.getTime()) / (1000 * 60 * 60 * 24));// 日期差45天

		List<Date> list = new ArrayList<Date>();

		Date ced = null;
		for (int i = 0; i < dc; i++) {
			Calendar ce = Calendar.getInstance();
			ce.setTime(endDate);
			ce.set(Calendar.DATE, ce.get(Calendar.DATE) + i);
			ced = ce.getTime();
			list.add(ced);
		}
		return list;
	}

	// 返回用户选择的日期轴(7天)
	public List<Date> getSevDayByChioce(String scopeTime) throws ParseException {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		List<Date> list = getDateList(30);
		List<Date> listSevDay = new ArrayList<Date>();
		for (Date d : list) {
			if (df.format(d).equalsIgnoreCase(scopeTime)) {
				Date ds = df.parse(scopeTime);
				Calendar c = Calendar.getInstance();
				c.setTime(ds);
				c.set(Calendar.DATE, c.get(Calendar.DATE) - 3);

				Date endDate = c.getTime();

				Calendar c2 = Calendar.getInstance();
				c2.setTime(ds);
				c2.set(Calendar.DATE, c2.get(Calendar.DATE) + 4);
				Date endDate2 = c2.getTime();

				int dc = (int) ((endDate2.getTime() - endDate.getTime()) / (1000 * 60 * 60 * 24));// 日期差45天

				Date ced = null;
				for (int i = 0; i < dc; i++) {
					Calendar ce = Calendar.getInstance();
					ce.setTime(endDate);
					ce.set(Calendar.DATE, ce.get(Calendar.DATE) + i);
					ced = ce.getTime();
					listSevDay.add(ced);
				}
			}
		}
		return listSevDay;
	}

	private static List<Date> getDateList(int dayNum) {
		Date nowDate = new Date();
		Calendar c = Calendar.getInstance();
		c.setTime(nowDate);
		c.set(Calendar.DATE, c.get(Calendar.DATE) + dayNum);
		Date endDate = c.getTime();
		int dc = (int) ((endDate.getTime() - nowDate.getTime()) / (1000 * 60 * 60 * 24));// 日期差45天
		List<Date> list = new ArrayList<Date>();
		Date ced = null;
		for (int i = 0; i < dayNum; i++) {
			Calendar ce = Calendar.getInstance();
			ce.setTime(nowDate);
			ce.set(Calendar.DATE, ce.get(Calendar.DATE) + i);
			ced = ce.getTime();
			list.add(ced);
		}
		return list;
	}

	public String getGrapDate() {
		return grapDate;
	}

	public void setGrapDate(String grapDate) {
		this.grapDate = grapDate;
	}

	public String getHdate() {
		return hdate;
	}

	public void setHdate(String hdate) {
		this.hdate = hdate;
	}

	public IndexPriceVo getPriceVo() {
		return priceVo;
	}

	public void setPriceVo(IndexPriceVo priceVo) {
		this.priceVo = priceVo;
	}

	public IndexPriceVo getOccupVo() {
		return occupVo;
	}

	public void setOccupVo(IndexPriceVo occupVo) {
		this.occupVo = occupVo;
	}

	public IndexPriceVo getIncomeVo() {
		return incomeVo;
	}

	public void setIncomeVo(IndexPriceVo incomeVo) {
		this.incomeVo = incomeVo;
	}

	public List<LowestPriceCompareVo> getVos() {
		return vos;
	}

	public void setVos(List<LowestPriceCompareVo> vos) {
		this.vos = vos;
	}

	public LowAnalyApplication getLowAnalyService() {
		return lowAnalyService;
	}

	public void setLowAnalyService(LowAnalyApplication lowAnalyService) {
		this.lowAnalyService = lowAnalyService;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public String getBeginDateAfterToday() {
		return beginDateAfterToday;
	}

	public void setBeginDateAfterToday(String beginDateAfterToday) {
		this.beginDateAfterToday = beginDateAfterToday;
	}

	public String getEndDateAfterToday() {
		return endDateAfterToday;
	}

	public void setEndDateAfterToday(String endDateAfterToday) {
		this.endDateAfterToday = endDateAfterToday;
	}

	public List<List<PlaneInfo>> getDataList() {
		return dataList;
	}

	public void setDataList(List<List<PlaneInfo>> dataList) {
		this.dataList = dataList;
	}

	public String getSope_Time() {
		return sope_Time;
	}

	public void setSope_Time(String sope_Time) {
		this.sope_Time = sope_Time;
	}

	public List<String> getListDate() {
		return listDate;
	}

	public void setListDate(List<String> listDate) {
		this.listDate = listDate;
	}

	public List<String> getList_str() {
		return list_str;
	}

	public String getDepCityCode() {
		return depCityCode;
	}

	public void setDepCityCode(String depCityCode) {
		this.depCityCode = depCityCode;
	}

	public String getArrCityCode() {
		return arrCityCode;
	}

	public void setArrCityCode(String arrCityCode) {
		this.arrCityCode = arrCityCode;
	}

	public int getIsCity() {
		return isCity;
	}

	public void setIsCity(int isCity) {
		this.isCity = isCity;
	}

	public void setList_str(List<String> list_str) {
		this.list_str = list_str;
	}

	public String getCompany_code() {
		return company_code;
	}

	public void setCompany_code(String company_code) {
		this.company_code = company_code;
	}

	public List<UserCareLineEntityVO> getCitylist() {
		return citylist;
	}

	public void setCitylist(List<UserCareLineEntityVO> citylist) {
		this.citylist = citylist;
	}

	public List<SourceEntityVO> getSourceLists() {
		return sourceLists;
	}

	public void setSourceLists(List<SourceEntityVO> sourceLists) {

		this.sourceLists = sourceLists;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getQrday() {
		return qrday;
	}

	public void setQrday(String qrday) {
		this.qrday = qrday;
	}

	public String getIdToaClass() {
		return idToaClass;
	}

	public void setIdToaClass(String idToaClass) {
		this.idToaClass = idToaClass;
	}

	public static List<PlaneInfo> getLowerList() {
		return lowerList;
	}

	public static void setLowerList(List<PlaneInfo> lowerList) {
		IndexAction.lowerList = lowerList;
	}

}

/**
 * 价格最低的排在前面
 */
class SortPriceLower implements Comparator<PlaneInfo> {
	@Override
	public int compare(PlaneInfo o1, PlaneInfo o2) {

		try {
			if (StringUtils.isEmpty(o1.getLowerPrice())) {
				System.err.println(o1);
				o1.setLowerPrice("0");
			}
			if (StringUtils.isEmpty(o2.getLowerPrice())) {
				o2.setLowerPrice("0");
			}
			int flag = Double.valueOf(o1.getLowerPrice()).compareTo(
					Double.valueOf(o2.getLowerPrice()));
			return flag;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
}

/**
 * 客座率高的排在前面
 */
class SortOccuHight implements Comparator<OccupRateEntityVO> {
	@Override
	public int compare(OccupRateEntityVO o1, OccupRateEntityVO o2) {
		Double i2 = 0d, i1 = 0d;
		if (o2.getOccupRate() == null) {
			i2 = 0d;
		} else {
			i2 = Double.valueOf(o2.getOccupRate() + "");
		}

		if (o1.getOccupRate() == null) {
			i1 = 0d;
		} else {
			i1 = Double.valueOf(o1.getOccupRate() + "");
		}
		int flag = i2.compareTo(i1);
		return flag;
	}
}

/**
 * 座公里数高的排在前面
 */
class SortIncomeHight implements Comparator<OccupRateEntityVO> {
	@Override
	public int compare(OccupRateEntityVO o1, OccupRateEntityVO o2) {
		Double i2 = 0d, i1 = 0d;
		if (o2.getIncome() == null) {
			i2 = 0d;
		} else {
			i2 = Double.valueOf(o2.getIncome() + "");
		}

		if (o1.getIncome() == null) {
			i1 = 0d;
		} else {
			i1 = Double.valueOf(o1.getIncome() + "");
		}
		// /int
		// flag=Double.valueOf(o2.getIncome()+"").compareTo(Double.valueOf(o1.getIncome()+""));
		int flag = i2.compareTo(i1);
		return flag;
	}

}
